﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Windows.Threading;
using System.Xml;
using System.IO;
using System.ServiceModel;

namespace BlastExplorer {
	/// <summary>
	/// Gets a GI number and Protein from GenomeDB.
	/// </summary>
	public partial class SimpleAccessionLoader: Window {
		private static string query = Settings.DefaultGI;
	
		public SimpleAccessionLoader () {
			InitializeComponent();

			queryField.Text = query;
			eValueCutoffField.Text = Settings.DefaultEValue.ToString();
			cddEValueCutoffField.Text = Settings.DefaultCddEValue.ToString();
			hitListSizeField.Text = Settings.DefaultHitListSize.ToString();
		}

		public void Initialise (
			double eValueCutoff,
			double cddEValueCutoff,
			int hitListSize,
			bool useBrowserProxy,
			Taxon[] selectedTaxa
		) {
			useBrowserProxyField.IsChecked = useBrowserProxy;
			eValueCutoffField.Text = eValueCutoff.ToString();
			cddEValueCutoffField.Text = cddEValueCutoff.ToString();
			hitListSizeField.Text = hitListSize.ToString();
			taxonField.SelectedTaxa = selectedTaxa;
		}

		private void Cancel_Click ( object sender, RoutedEventArgs e ) {
			this.DialogResult = false;
		}

		private void Load_Click ( object sender, RoutedEventArgs e ) {
			query = queryField.Text.Trim();
			this.DialogResult = true;
		}

		static public string Query {
			get {
				return query;
			}
			set {
				query = value;
			}
		}

		public bool UseBrowserProxy {
			get {
				return useBrowserProxyField.IsChecked == true;
			}
		}

		/// <summary>
		/// Gets a new array containing the tax id's of the selected taxa.
		/// </summary>

		public Taxon [] SelectedTaxa {
			get {
				return taxonField.SelectedTaxa;
			}
		}

		#region Property: EValueCutoff
		/// <summary>
		/// Gets the E-value cutoff.
		/// </summary>

		public double EValueCutoff {
			get {
				try {
					return double.Parse( eValueCutoffField.Text );
				}
				catch {
					return Settings.DefaultEValue;
				}
			}
		}
		#endregion

		#region Property: CddEValueCutoff
		/// <summary>
		/// Gets the Cdd E-value cutoff.
		/// </summary>

		public double CddEValueCutoff {
			get {
				try {
					return double.Parse( cddEValueCutoffField.Text );
				}
				catch {
					return Settings.DefaultCddEValue;
				}
			}
		}
		#endregion
		
		/// <summary>
		/// Gets the hit list size.
		/// </summary>
		
		public int HitListSize {
			get { 
				try {
					return int.Parse( hitListSizeField.Text );
				}
				catch {
					return Settings.DefaultHitListSize;
				}
			}
		}
	}
}
